<?php


namespace app\admin\controller;


use app\admin\business\freightBus;
use app\BaseController;
use think\facade\View;

class Freight extends BaseController
{
    public function index(){
        return View::fetch();
    }
    public function getList(){
        $paging = $this->request->param('paging');
        $title = $this->request->param('title');
        $end_time = $this->request->param('end_time');
        $start_time = $this->request->param('start_time');
        $status = $this->request->param('status');
        $where = [];
        if($status != 0){
            $where = [
                'status' => $status
            ];
        }
        $freightBus = new freightBus();
//        dump($where);exit();
        try {
            $result = $freightBus->getAllListPage($title,$start_time,$end_time,$paging,$where);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
//        $result = $memberBus->with('profile')->select();
        return show(config('status.success'),'获取成功',$result);
    }
    public function detail(){
        $id = $this->request->param("id");
        View::assign("id",$id);
        return View::fetch();
    }
    public function getItemDetail(){
        $id = $this->request->param('id');
        $freightBus = new freightBus();
        try {
            $result = $freightBus->getItemByIdBus($id);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'获取成功',$result);
    }
    public function changeStatus(){
        $where = $this->request->param('where');
        $saveData = $this->request->param('saveData');
        $freightBus = new freightBus();
        try {
            $result = $freightBus->changeStatusBus($where,$saveData);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'获取成功',$result);
    }
    public function removeFreight(){
        $id = $this->request->param('id');
        $freightBus = new freightBus();
        try {
            $result = $freightBus->removeFreightBus($id);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'删除成功',$result);
    }
    public function Apply(){
        $id = $this->request->param('id');
        View::assign('id',$id);
        return View::fetch();
    }
    public function getApplyMemberList(){
        $id = $this->request->param('id');
        $current_page = $this->request->param('current_page');
        $num = $this->request->param('num');
        $where = [
            'consignor_item_id'=>$id
        ];
        $paging = [
            'current_page'=>$current_page,
            'num' => $num
        ];
        $freightBus = new freightBus();
        try {
            $result = $freightBus->getApplyMemberListBus($where,$paging);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'删除成功',$result);
    }
}